package com.stedu.service.Impl;

import com.stedu.bean.Characters;
import com.stedu.exception.SteduException;
import com.stedu.mapper.CharactersMapper;
import com.stedu.service.CharactersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CharactersServiceImpl implements CharactersService {
    @Autowired
    private CharactersMapper charactersMapper;
    @Override
    public long findCount(String cname, String gname)  {
        return charactersMapper.selectCount(cname, gname);
    }

    @Override
    public boolean addcharacters(Characters characters)  {
        characters.setCban(1);
        return charactersMapper.addcharacters(characters)==1?true:false;
    }

    @Override
    public boolean delete(Long cid)  {
        return charactersMapper.updatchart(cid, 2)==1?true:false;
    }

    @Override
    public boolean updatecharacters(Characters characters) throws  SteduException {
        if (charactersMapper.selectBycid(characters.getCid())==null){
            throw new SteduException("该人物不存在，无法删除");
        }
        return charactersMapper.updatecharacters(characters)==1?true:false;
    }

    @Override
    public List<Characters> selectall( String cname,  String gname)  {
        return charactersMapper.selectchoice(cname, gname);
    }

    @Override
    public Characters selectById(Long cid)  {
        return charactersMapper.selectBycid(cid);
    }

    @Override
    public String selectgname(Integer gid)  {
        return charactersMapper.selectgname(gid);
    }
}
